﻿using System;
using System.IO;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;

namespace SeleniumTest
{
    [TestClass]
    public class TestOrganization
    {
        private ChromeDriver driver;
        string path;
        [TestInitialize]
        public void Setup()
        {
            string projectname = "seleniumtesting111";
            string path = Directory.GetCurrentDirectory().Substring(0, Directory.GetCurrentDirectory().LastIndexOf(@"seleniumtesting111") + projectname.Length);
            ChromeOptions incognito = new ChromeOptions();
            incognito.AddArgument("--incognito");
            driver = new ChromeDriver(path, incognito);
            string baseURL = "localhost:8080";
            driver.Navigate().GoToUrl(baseURL);
        }

        [TestCleanup]
        public void CleanUp()
        {
            driver.Quit();
        }

        [TestMethod]
        [Description("Test that the list of organization is present")]
        public void TestOrganizationList()
        {
            driver.FindElement(By.LinkText("ORGANISATIONER")).Click();
            var elem = driver.FindElement(By.ClassName("organizationBox")).Displayed;
            Assert.IsTrue(elem);
        }

        [TestMethod]
        [Description("Test the detailed organization view")]
        public void TestOrganizationDetailedView()
        {
            driver.FindElement(By.LinkText("ORGANISATIONER")).Click();
            driver.FindElementByClassName("organizationlist").FindElement(By.PartialLinkText("Børnefonden")).Click();
            var elem = driver.FindElement(By.Id("organization-detail")).Displayed;
            Assert.IsTrue(elem);
        }
    }
}
